<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="btn">提交</button>

  <script>
    let btn = document.getElementById('btn')

    btn.addEventListener('click', throttle(handle, 1000))

    function handle(e, a, b) {
      console.log('提交了', this);
    }


    function debounce(fn, wait) {
      let timer = null
      return function(...args) { // this === btn
        // 销毁上一次的定时器
        clearTimeout(timer)

        timer = setTimeout(() => {
          fn.call(this, ...args)
        }, wait)
      }
     
    }
  
    function throttle(fn, wait) { // 
      let pre = Date.now()   // 1
      return function(...args) {
        let cur = Date.now()  // 3  // 3.1
        if (cur - pre > wait) {
          fn.call(this, ...args)
          pre = cur
        }
        
      }
    }
  </script>
</body>
</html>